<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>跨域请求示例</h1>
    <button id="fetchDataBtn">获取数据</button>
    <div id="result"></div>

    <script>
        document.getElementById('fetchDataBtn').addEventListener('click', fetchData);

        function fetchData() {
            fetch('https://demo.codelover.club/api/curriculum/50', {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
                credentials: 'include' // 如果需要发送cookie或其他凭证
            })
                .then(response => {
                    if (!response.ok) {
                        throw new Error('网络响应失败');
                    }
                    return response.json();
                })
                .then(data => {
                    document.getElementById('result').innerText = JSON.stringify(data, null, 2);
                })
                .catch(error => {
                    console.error('请求失败:', error);
                });
        }
    </script>
</body>

</html>